ROOT_DIR := $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
DATA_DIR := $(ROOT_DIR)/data

CATEGORY_NAME :=  biology \
				  classic \
				  crypto  \
				  dsp     \
				  linalg  \
				  media   \
				  physics \
				  sci_calc

CMD := vitis_hls -f build.tcl

COLOR_RED   = \033[1;31m
COLOR_GREEN = \033[1;32m
COLOR_NONE  = \033[0m

RESULT = $(ROOT_DIR)/.result

build:
	python src/main.py

DATA := $(shell find $(DATA_DIR) -mindepth 2 -maxdepth 2 -type d)

count:
	@echo $(DATA) | tr ' ' '\n' | sed 's:.*/\([^/]\+/[^/]\+\)$$:\1:'
	@echo $(DATA) | tr ' ' '\n' | wc -l

vitis_build: $(DATA)
	@for d in $^; do \
		echo "==> Building in $$d"; \
		cd $$d; \
		if $(CMD); then \
			printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE)\n" $$d >> $(RESULT); \
		else \
			printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $$d >> $(RESULT); \
		fi; \
		cd - >/dev/null; \
	done

run_test: vitis_build
	@cat $(RESULT)
	@rm $(RESULT)

clean: $(DATA)
	find . -type f -name "vitis_hls.log" -delete
	@echo Clear all built vitis HLS project
	@for d in $^; do \
		cd $$d; \
		rm -rf `basename $$d`; \
		cd - >/dev/null; \
	done
